package com.example.imtoken.modules.login

import com.blankj.utilcode.util.ActivityUtils
import com.blankj.utilcode.util.ClickUtils
import com.blankj.utilcode.util.ClipboardUtils
import com.example.imtoken.R
import com.example.imtoken.core.base.BaseActivity
import com.example.imtoken.databinding.ActivityLoginBinding
import com.example.imtoken.modules.user.create.CreateUserActivity
import com.example.imtoken.modules.user.recovery.RecoveryUserActivity

class LoginActivity :
    BaseActivity<LoginViewModel, ActivityLoginBinding>(LoginViewModel::class.java) {

    private val exit by lazy {
        intent.getBooleanExtra("exit", false)
    }

    val uri = "http://www.baidu.com?xxxxx=170069&down"

    override fun initLayoutId(): Int {
        return R.layout.activity_login
    }

    override fun init() {
        if (exit) ActivityUtils.finishAllActivitiesExceptNewest()

        //设置沉浸式状态栏
        initBar()

        initClick()

        dataBinding.activity = this


        //获取剪切板上的链接
//        val codeURI = ClipboardUtils.getText()
        viewModel.getExtensionCode(uri)

        viewModel.getBannerData()

        viewModel.getBannerLiveData().observe(this) {
            dataBinding.bvpLanding.apply {
                setAdapter(LoginBannerAdapter())
                setLifecycleRegistry(lifecycle)
            }.create(it)
        }
    }

    private fun initClick() {
        ClickUtils.applyGlobalDebouncing(dataBinding.llCreateUser) {
            ActivityUtils.startActivity(CreateUserActivity::class.java)
        }
        ClickUtils.applyGlobalDebouncing(dataBinding.llRecoveryUser) {
            ActivityUtils.startActivity(RecoveryUserActivity::class.java)
        }
    }

    override fun onPause() {
        dataBinding.bvpLanding.stopLoop()
        super.onPause()
    }

    override fun onResume() {
        super.onResume()
        dataBinding.bvpLanding.startLoop()
    }

    override fun onDestroy() {
        super.onDestroy()
        dataBinding.bvpLanding.stopLoop()
    }

}